package com.xlh.dao.conclude.helper;

import cn.hutool.core.collection.CollectionUtil;
import com.xlh.dao.conclude.ConcludeSubCourseMapper;
import com.xlh.pojo.conclude.ConcludeSubCourse;
import com.xlh.pojo.conclude.example.ConcludeSubCourseExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author cfz
 */
@Repository
public class ConcludeSubCourseMapperHelper {


    @Autowired
    private ConcludeSubCourseMapper concludeSubCourseMapper;


    public void insertBatch(List<ConcludeSubCourse> concludeSubCourses) {
        for (ConcludeSubCourse concludeSubCours : concludeSubCourses) {
            concludeSubCourseMapper.insertSelective(concludeSubCours);
        }
    }

    /**
     * 根据subId 进行删除
     * @param subIds
     */
    public void deleteBySubId(List<Long> subIds) {

        ConcludeSubCourse record = new ConcludeSubCourse();
        record.setIsDelete(true);
        ConcludeSubCourseExample example = new ConcludeSubCourseExample();
        example.createCriteria().andIsDeleteEqualTo(false).andCheckSubIdIn(subIds);
        concludeSubCourseMapper.updateByExampleSelective(record, example);
    }

    /**
     * 根据subId 进行删除
     * @param courseIds
     */
    public void deleteByCourseId(List<Long> courseIds) {

        ConcludeSubCourse record = new ConcludeSubCourse();
        record.setIsDelete(true);
        ConcludeSubCourseExample example = new ConcludeSubCourseExample();
        example.createCriteria().andIsDeleteEqualTo(false).andConCourseIdIn(courseIds);
        concludeSubCourseMapper.updateByExampleSelective(record, example);
    }





    /**
     * 查询根据考核分项ID
     * @param id
     * @return
     */
    public List<ConcludeSubCourse> findBySubId(Long id) {

        ConcludeSubCourseExample example = new ConcludeSubCourseExample();
        example.createCriteria().andIsDeleteEqualTo(false).andCheckSubIdEqualTo(id);
        return concludeSubCourseMapper.selectByExample(example);
    }


    /**
     * 根据考核分项ID和 课程目标ID
     * @param subId
     * @param conCourseId
     * @return
     */
    public ConcludeSubCourse findBySubIdAndCourseId(Long subId, Long conCourseId){

        ConcludeSubCourseExample example = new ConcludeSubCourseExample();
        example.createCriteria().andIsDeleteEqualTo(false)
                .andCheckSubIdEqualTo(subId)
                .andConCourseIdEqualTo(conCourseId);
        List<ConcludeSubCourse> concludeSubCourses = concludeSubCourseMapper.selectByExample(example);

        if(CollectionUtil.isNotEmpty(concludeSubCourses)){
            return concludeSubCourses.get(0);
        }
        return null;
    }

    /**
     * 获取和
     * @param conCourseIds
     * @return
     */
    public List<ConcludeSubCourse> findByCourseId(List<Long> conCourseIds){

        ConcludeSubCourseExample example = new ConcludeSubCourseExample();
        example.createCriteria().andIsDeleteEqualTo(false).andConCourseIdIn(conCourseIds).andCourseWeightIsNotNull();
        List<ConcludeSubCourse> concludeSubCourses = concludeSubCourseMapper.selectByExample(example);

        return concludeSubCourses;
    }




}
